from traitlets import Unicode

from jupyterhub.auth import Authenticator
import requests
import json
import os
from tornado import gen

origin = os.environ.get("CODEHUB_BACKEND")
class DummyAuthenticator(Authenticator):

    @gen.coroutine
    def authenticate(self, handler, data):
        #if data['username']:
        #   return data['username']
        #else:
        
        headers = {"Content-Type": "application/json",}
        datas = json.dumps({"userID": data['userID']})
        req = requests.post(
                origin+'/getSTDNum',
            data=datas,
            headers=headers,
        )
        print("19030500236")
        STDNum = req.text.strip('"')
        print(STDNum)
        if STDNum[0] == '错':
            raise Exception("错误的userID")
        else:
            return STDNum
